
//增加cookie
function addCookie(key, val, day) { //key必须输入String类型
    if (day) {
        var date = new Date();
        date.setDate(date.getDate() + day);
        document.cookie = key + "=" + val + ";expires=" + date;
    } else {
        document.cookie = key + "=" + val;
    }
}

//获得cookie
function getCookie(key) { //key需要输入String类型
    var data = document.cookie;
    var arr = data.split("; ");
    for (var i = 0; i < arr.length; i++) {

        var value = arr[i].split("=");

        if (value[0] == key) {
            return value[1];
        }

    }

    return "";

}
//删除cookie
function delCookie(key) {
    addCookie(key, "", -1)
}

export {
    addCookie,getCookie,delCookie
}